﻿
function InitWorkReport(row) {
    $.ajax({
        url: "/AJAX/AjaxService.aspx?method=GetTask_",
        cache: false,
        type: "post",
        data: { task_id_: row.task_id_ },
        success: function (text) {
            var obj = mini.decode(text);

            document.getElementById("txt_task_name_").innerText = obj.data[0].task_name_;
            document.getElementById("txt_description_").innerText = obj.data[0].description_;
            document.getElementById("txt_status").innerText = FormatTaskStatus(obj.data[0].status_) + GetDelay(obj.data[0].estimated_end_time_, obj.data[0].status_);
            document.getElementById("txt_assign_user_name_").innerText = obj.data[0].assign_user_name_;
            document.getElementById("txt_estimated_start_time_").innerText = new Date(obj.data[0].estimated_start_time_).Format("yyyy-MM-dd");
            var cc = document.getElementById("txt_cc");
            var ccNames = "";
            for (var c = 0; c < obj.dtTu.length; c++) {
                ccNames += obj.dtTu[c].task_user_name_ + ",";
            }
            if (ccNames.length > 0) {
                ccNames = ccNames.substring(0, ccNames.length - 1);
            }
            cc.innerText = ccNames;

            document.getElementById("txt_estimated_end_time_").innerText = new Date(obj.data[0].estimated_end_time_).Format("yyyy-MM-dd");
            mini.get("spTaskProgress").setValue(obj.data[0].progress_);
            InitSubTaskTimeLine(obj.data[0].task_id_, 0, 1);

        }
    });
}

function InitSubTaskTimeLine(task_ID, pageIndex, startIndex) {
    $("#d_more").remove();
    $("#d_timeline_more").remove();
    //只需要取周汇报即可
    $.ajax({
        url: "/AJAX/AjaxService.aspx?method=GetUserNameAndTaskTimeLine",
        cache: false,
        type: "post",
        data: {
            task_id_: task_ID,
            type_: 0,
            pageIndex: pageIndex,
            pageSize: 3,
            sortField: "start_time_",
            sortOrder: "DESC"
        },
        success: function (text) {
            var obj = mini.decode(text);
            var layer = '';
            for (var i = 0; i < obj.data.length; i++) {
                layer += '<div class="i_talking_content"><span class="i_hover_color">' + (obj.data[i].update_date_ == null ? "" : new Date(obj.data[i].update_date_).Format("yyyy-MM-dd hh:mm:ss")) + '</span></div>'
                layer += '<div class="i_talking_info"><span><b style="color:#787878">' + obj.data[i].user_name_ + ':</b></span>';
                layer += '<span class="i_talking_content"><textarea style=" word-break: break-all;word-wrap: break-word;" class="mini-textarea i_input_textarea_per" allowresize="false" readonly="readonly">' + (obj.data[i].work_report_ == null ? "" : obj.data[i].work_report_) + '</textarea></span></div>';
            }
            if (layer.length <= 0) {
                layer = '<div align="center">无相关信息</div>';
            } else {
                if (!((pageIndex + 1) * 3 >= obj.total)) {
                    layer += "<div class=\"i_td_left i_td_center\" id=\"d_more\"><a href=\"javascript:InitSubTaskTimeLine(" + task_ID + "," + (pageIndex + 1) + "," + startIndex + ")\">点击加载更多...</a></div>";
                }
            }
            $("#d_timeline").append(layer);
        }
    });
}

function rowClick() {
    var tree = mini.get("treegrid_subtask");
    var row = tree.getSelected();
    document.getElementById("d_timeline").innerHTML = "";
    InitWorkReport(row);
}